/***************************************************************************
 *   Copyleft 2008-2009 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#include "./vTimer.h"

namespace Vendetta {
	vTimer::vTimer():mStartTime(0), mPerFrameTime(0), mPrevPerFrameTime(0),	mFPS(0),
		mFrameTime(0), mFramesCounter(0), mLastFPSRefreshTime(0) {
		for (vInt i = 0; i < NUM_FPS_FRAMES; i++) {
			mPrevFrameTimes[i] = 0;
		}
	}

	vTimer::~vTimer()	{
	}

	vInt vTimer::Time() const	{
		return mPerFrameTime;
	}


	vReal vTimer::FPS() const	{
		return mFPS;
	}

	vReal vTimer::FrameTime() const	{
		return mFrameTime;
	}

	vReal vTimer::PrevFrameTime() const	{
		return mPrevFrameTime;
	}

	vInt vTimer::FramesCount() const	{
		return mFramesCounter;
	}

	vString vTimer::ToString(vUInt time) const {		
		vChar buff[100];
												time /= 10;
		const vInt	miliSeconds	= time % 100;	time /= 100;
		const vInt	seconds		= time % 60;	time /= 60;
		const vInt	minutes		= time % 60;	time /= 60;
		const vInt	hours		= time % 24;

		sprintf_s(buff, "%d:%02d:%02d:%02d", hours, minutes, seconds, miliSeconds);
		
		vString string = buff;

		return string;

	}
}